package com.library.controller;

import com.library.bean.User;
import com.library.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Resource
    private UserService userService;


    @RequestMapping("/login")
    public String login(User user, Model model, HttpSession session){
        User loginUser = userService.LoginUser(user);
        if (loginUser==null){
            model.addAttribute("msg","用户名或者密码错误");
            return "login.jsp";
        }
        session.setAttribute("user",loginUser);
        return "books.jsp";
    }
}
